<template>
    <div>
        <h3>欢迎光临水果店</h3>
        <table>
            <tr>
                <th>苹果{{ price }}￥/斤,折扣{{ discount }}折</th>
            </tr>
            <tr>
                <td>请输入您要购买的斤数<input type="text" v-model.number="buyNum" /></td>
            </tr>
            <tr>
                <td><button @click="Closing">结账买单</button></td>
            </tr>
            <tr>
                <td>结账单:总价{{ totalPrice }}￥元 折后价:{{ afterDiscount }} ￥元 省了:{{ save }}￥元</td>
            </tr>
        </table>
    </div>
</template>

<script>
export default {
    name: '',
    components: {},
    props: {},
    data() {
        return {
            price: 10,
            buyNum: '',
            discount: 8,
            totalPrice: '',
            afterDiscount: '',
            save: '',
        }
    },
    computed: {},
    watch: {},
    created() {},
    methods: {
        Closing() {
            if (!this.buyNum) return
            this.totalPrice = (this.buyNum * this.price).toFixed(2)
            this.afterDiscount = (this.totalPrice * this.discount * 0.1).toFixed(2)
            this.save = (this.totalPrice - this.afterDiscount).toFixed(2)
        },
    },
}
</script>

<style scoped>
table {
    text-align: center;
    background-color: skyblue;
    color: #eee;
    border: 1px solid #000;
    width: 500px;
    height: 500px;
    font-size: 18px;
}
th,
td {
    height: 100px;
}
</style>
